// import Abnormalvideofloor from '../../src/components/Home/energy/energyfloor.vue'
var g_binhaiSceneDatas  = new Array();// binhai_xx.json---MultiPolygon数据
var g_smallFloorDatas   = new Array();// all.json---MultiPolygon数据 其他
var g_MLSDatas          = new Array();//包含所有文件的MultiLineString数据
var g_MPointDatas       = new Array();//包含所有文件的MultiPoint数据
var g_bigFloorDatas     = new Array();//B4--F50所有楼层文件

var g_selectableMPolygons   = new THREE.Group();
var g_binhaiSceneMPolygons  = new THREE.Group();// binhai_xx.json
var g_smallFloorMPolygons   = new THREE.Group();// all.json 其他
var g_MLSs                  = new THREE.Group();
var g_MPoints               = new THREE.Group();
//var g_bigFloorMPolygons     = new THREE.Group();//B4--F50所有楼层文件
var g_bigFloorWallMPolygons = new THREE.Group();//B4--F50所有楼层墙文件 
var g_bigFloorBoardMPolygons = new THREE.Group();//B4--F50所有楼层地板文件 
var g_bigFloorRoomMPolygons  = new THREE.Group();//B4--F50所有楼层房间文件
var g_jsonNameAttrs         = [];//所有文件中json.name属性
var g_frameMPolygons        = new THREE.Group();
var g_contour               = new THREE.Group();

var g_files           = [];
var g_sceneAdded      = false;

var g_UnusualVideogroup = new THREE.Group();
var g_textgroup = new THREE.Group();

var g_stats;
var g_renderer;
var g_scene;
var camera;
var controls;
//var g_dat;
var g_selectingMat          = new THREE.MeshPhongMaterial({
    color:0xff0000,
    transparent:true,
    opacity:0.1,
    shininess:2000.0,
    specular: 0x666666
});
var g_binhaiSceneMat        = new THREE.MeshPhongMaterial({
    color:0xff0000,
    transparent:true,
    opacity:0.1
});
var g_lineMat               = new THREE.LineBasicMaterial({
    color:0xafafaf,
    transparent:true,
    opacity:0.05,
    linewidth:2
});
var g_pointsMat             = new THREE.PointsMaterial( {
    size: 1,
    vertexColors: THREE.VertexColors
} );
// var g_bigFloorMat           = new THREE.MeshPhongMaterial({
//     color:0xff0000,
//     transparent:true,
//     opacity:0.1
// });
//单层材质
var g_bigFloorBoardMat           = new THREE.MeshPhongMaterial({
    color:0x111111
});
var g_bigFloorWallMat           = new THREE.MeshPhongMaterial({
    color:0x00ff00,
    side:THREE.DoubleSide
});
var g_bigFloorRoomMat           = new THREE.MeshPhongMaterial({
    color:0x00ff00
});
var g_frameMat              = new THREE.MeshPhongMaterial({
    color:0xff0000,
    transparent:true,
    opacity:0.1
});

var g_sandiangroup = new THREE.Group();
var scatterMapvertices =  [];
var scatterMapcolors  =[];

var g_ambientL;
var g_spotLight;
var g_floorDLight = new THREE.DirectionalLight( 0xffffff,2 );  //单层平行光
var raycaster;
var mouse = new THREE.Vector2();
var g_recordSelectedMesh = null;  //记录选中物体
var g_lastRecordSelectedMesh = null;
var g_recordSelectedMat;

//test
var farview = false;
var nearview = false;
var targetCameraX  = 90;
var targetCameraY  = 90;
var targetCameraZ  = 90;
var originCameraX  = 0;
var originCameraY  = 0;
var originCameraZ  = 0;
var g_step = 100;
var deltaX = 1;
var deltaY = 1;
var deltaZ = 1;
var g_countX = 0;
var g_keySpace = false;
var defaultCenterVeiw = new THREE.Vector3(100,100,100);//默认相机视点
var heatplanlist = [];
var heatplane = []; 

var g_contourColor = [];
var g_contourData = new Map();
var g_LevelNum = 100;
var g_contourKeys = [];
var g_contourIndex = 0;
var f_pageType = 1;
var f_subPageType = 0;
var f_FloorOrBudling = 0;
var g_floorNumTextGroup = new THREE.Group();

var g_globalVar = new GlobalVar(); 
var g_changeViewByNum = false;

var g_recvFileNum=0;
var g_frontEndCB;
function registerFrontEndCB(f) {
    g_frontEndCB = f;
}
var fileSum = 0;
var fileNumIndex = 0;
function frontEndCB(fileSum, fileNumIndex) {
    //  总json数量   正在加载的json数量   json文件名称
    Vue.$store.state.threeD.loding.fileSum = fileSum
    Vue.$store.state.threeD.loding.fileNumIndex = fileNumIndex
    console.log(Vue.$store.state.threeD.loding.fileSum,Vue.$store.state.threeD.loding.fileNumIndex)
    // document.cookie="fileSum="+fileSum
    // document.cookie="fileNumIndex="+fileNumIndex
    // var username=Number(document.cookie.split(";")[0].split("=")[1])
    // var username1=Number(document.cookie.split(";")[1].split("=")[1])
    // console.log(username,username1);
    // console.log(Vue.$store.state.threeD.loding.fileSum,Vue.$store.state.threeD.loding.fileNumIndex);
}
function generateContourRGB() {//使用0.0~1.0的范围，更简单
    var colorR  = new Array();
    var colorY  = new Array();
    var colorB  = new Array();

    var deltaV  = 256/g_LevelNum, col;
    for(var i=0; i<g_LevelNum; i++){
        var d = Math.round(i*deltaV);
        col = 0xffffff -  d*256 - d;
        colorR.push(col);

        col = 0xffffff - d;
        colorY.push(col);

        col = 0xffffff - d*65536 - d*256;
        colorB.push(col);
    }

    g_contourColor.push(colorR);
    g_contourColor.push(colorY);
    g_contourColor.push(colorB);
}
function parseContourData(jsonObj){
//////////------------  json内容   -----------------------------
    var code = jsonObj.code;
    var msg  = jsonObj.message;


    for (var t in jsonObj.data) {//t:日期+时间 as key
        var tData = new  Map();
        for (var l in jsonObj.data[t]){//l:楼层号 as key
            var v0 = new THREE.Vector2();
            var v1 = new THREE.Vector2();
            var ds = jsonObj.data[t][l];
            if(ds[0].coordinate.y < ds[1].coordinate.y){//判断楼左侧还是右侧
                v0.x = ds[0].weight;
                v0.y = ds[0].level;
                v1.x = ds[1].weight;
                v1.y = ds[1].level;
            }else {
                v0.x = ds[1].weight;
                v0.y = ds[1].level;
                v1.x = ds[0].weight;
                v1.y = ds[0].level;
            }
            tData.set(l, [v0, v1]);//先存左侧
        }

        g_contourData.set(t, tData)
    }
//////////------------  json内容   -----------------------------

    for(var k of g_contourData.keys())
        g_contourKeys.push(k);

    g_frontEndCB(g_files.length+1,  ++g_recvFileNum, "null");
}
// 大概思路：先读取geojson数据，然后存入多维数组，再将多维数组传入3d引擎并遍历数据进行绘制。
function parseData(jsonObj){
//////////------------  json内容   -----------------------------
    //console.log("type:" + jsonObj.type);
    //console.log("name:" + jsonObj.name);
    //console.log("crs type:" + jsonObj.crs.type);
    //console.log("crs properties name:" + jsonObj.crs.properties.name);

    var binhaiSceneData     = new Array();//
    var smallFloorData      = new Array();//包含当前文件的MultiPolygon数据XXX
    var MultiLineStringData = new Array();//包含当前文件的MultiLineString数据
    var MultiPointData      = new Array();//包含当前文件的MultiPoint数据
    var bigFloorData        = new Array();//B4--F50的某一楼层文件
    var eid;
    var idType;
    var idNum;

    for (var i_l1 in jsonObj.features) {
        var feature = jsonObj.features[i_l1];
        //console.log("features type:" + feature.type);
        //console.log("features geometry type:" + feature.geometry.type);
        //console.log("features properties eid:" + feature.properties.eid);

        eid = feature.properties.eid;//binhai文件没有eid值，具体楼层文件部分geometry没有eid值
        if(eid == undefined){
            idType = -1;
            idNum  = -1;
        }else {
            idType  = parseInt(eid.substr(eid.length-6, 3));
            idNum   = parseInt(eid.substr(eid.length-3, 3));
        }
        if(idNum > 40)//文件中eid没有40
            idNum -= 1;
        //parseXX函数对应文件中一个geometry
        switch(feature.geometry.type)
        {
            case "MultiPolygon"://binhai、B4--F50所有楼层文件的数据，其格式与all不一致
            {
                var num = parseInt(jsonObj.name.substr(jsonObj.name.length-1));
                var shortEid = 1000000 + idType*1000 + idNum;//eid编凑规则： 1/2 + 220/221 + 000
                var datas = parseMultiPolygon(feature.geometry, jsonObj.name);
                if(num <= 9 && num >= 0)
                    bigFloorData.push(datas);
                else if(idType == 220)
                    smallFloorData.push([shortEid, datas]);
                else if(idType == 221)
                    smallFloorData.push([shortEid, datas]);
                else
                    //binhaiSceneData.push(datas);
                    binhaiSceneData.push([shortEid, datas]);//20180611 为了不采用O函数
            }
                break;
            case "MultiLineString":
                MultiLineStringData.push(parseMultiLineStringO(feature.geometry));
                break;
            case "MultiPoint":
                MultiPointData.push(parseMultiPoint(feature.geometry));
                break;
            default:
                console.log("未解析的类型");
                break;
        }
    }
    g_binhaiSceneDatas.push(binhaiSceneData);
    g_smallFloorDatas.push(smallFloorData);
    g_MLSDatas.push(MultiLineStringData);
    g_MPointDatas.push(MultiPointData);
    g_bigFloorDatas.push(bigFloorData);
    g_jsonNameAttrs.push(name2eid(jsonObj.name));
    //////////------------  json内容   -----------------------------
    g_frontEndCB(g_files.length+1,  ++g_recvFileNum, "null");
}
//eid编凑规则：第一位：1表示楼左侧或无左右之分，默认值/2表示楼右侧
//第二到四位：220表示地下，221表示地上
//第五到七位：表示楼层号
function name2eid(name) {
    var minus = name.substr(name.length - 1, 1);
    name = name.replace(/-/ig, "");

    var eid = 0;
    var lengthName = name.length;
    var bf = name.substr(name.length - 2, 1);
    var bf2 = name.substr(name.length - 3, 1);

    var str = name.replace(/[^0-9]/ig, "");
    var num = parseInt(str);

    if (lengthName == 2) { //eid编凑规则： 1/2 + 220/221 + 000
        if (bf == 'B')
            eid = 1220000 + num;
        else if (bf == 'F')
            eid = 1221000 + num;
    } else if (lengthName == 3) {
        if (bf2 == 'F')
            eid = 1221000 + num;
    }

    var s = eid.toString();
    if (minus == "-")
        s = s.replace(/\d/, "2");

    return s;
}
function initializeDAT() {

    var nameUG      = "underground";
    var nameF3to6   = "F3to6";
    var nameF21to26 = "F21to26";
    var nameF34to38 = "F34to38";
    var nameOtherFloor  = "OtherFloor";
    var nameOther   = "Other";

    var dataUG      = ["B1", "B2", "B3", "B4"];
    var dataF3to6   = ["F3", "F4", "F5", "F6"];
    var dataF21to26 = ["F21", "F22", "F23", "F24", "F25", "F26"];
    var dataF34to38 = ["F34", "F35", "F36", "F37", "F38"];
    var dataOtherFloor = ["F1", "F2", //one

        "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17",//two
        "F7-", "F8-", "F9-", "F10-", "F11-", "F12-", "F13-", "F14-", "F15-", "F16-", "F17-",//two
        "F18", "F19", "F20", "F27", "F28", "F29", "F30", "F31", "F32", "F33", "F39", "F40", "F41",//two
        "F18-", "F19-", "F20-", "F27-", "F28-", "F29-", "F30-", "F31-", "F32-", "F33-", "F39-", "F40-", "F41-",//two

        "F42", "F43", "F44", "F45", "F46", "F47", "F48", "F49", "F50"];//one
    var dataOther = ["selecting", "binhaiScene", "binhaiLine", "points", "bigfloorBoard", "bigfloorWall", "bigfloorRoom", "frame"];

    var nameStr = [];
    nameStr.push.apply(nameStr, dataUG);
    nameStr.push.apply(nameStr, dataF3to6);
    nameStr.push.apply(nameStr, dataF21to26);
    nameStr.push.apply(nameStr, dataF34to38);
    nameStr.push.apply(nameStr, dataOtherFloor);
    nameStr.push.apply(nameStr, dataOther);

    var mat = [];
    var obj = [];
    for (var str of nameStr) {
        for (var k = 0; k < g_smallFloorMPolygons.children.length; k++) {
            if (name2eid(str) == g_smallFloorMPolygons.children[k].name) {
                obj.push(g_smallFloorMPolygons.children[k]);
                mat.push(g_smallFloorMPolygons.children[k].material);
            }
        }
    }
    obj.push(g_recordSelectedMesh);
    obj.push(g_binhaiSceneMPolygons);
    obj.push(g_MLSs);
    obj.push(g_MPoints);

    obj.push(g_bigFloorBoardMPolygons);
    obj.push(g_bigFloorWallMPolygons);
    obj.push(g_bigFloorRoomMPolygons);

    obj.push(g_frameMPolygons);
    mat.push(g_selectingMat);
    mat.push(g_binhaiSceneMat);
    mat.push(g_lineMat);
    mat.push(g_pointsMat);

    mat.push(g_bigFloorBoardMat);
    mat.push(g_bigFloorWallMat);
    mat.push(g_bigFloorRoomMat);
    mat.push(g_frameMat);

    option = {
        groups: [
            {name:nameUG,           data:dataUG},
            {name:nameF3to6,        data:dataF3to6},
            {name:nameF21to26,      data:dataF21to26},
            {name:nameF34to38,      data:dataF34to38},
            {name:nameOtherFloor,   data:dataOtherFloor},
            {name:nameOther,        data:dataOther},
        ],   //对象名称，用来识别对象和作为保存加载ID
        name: nameStr,
        material: mat,
        object: obj,  //对象
        scene: g_scene,  //场景
        camera: camera,
        light: [g_ambientL, g_spotLight],  //光照
        renderer: g_renderer
    };

    
    WEBUILDING3D.initalLoading(option,WEBUILDING3D.DefaultMaterial);  
}
function createSceneDynamicly() {
    if (g_files.length == g_smallFloorDatas.length && g_files.length != 0 && !g_sceneAdded) {
        g_sceneAdded = true;

        createMP();

        for (var j = 0; j < g_MLSDatas.length; j++) {
            createMultiLineStringO(g_MLSDatas[j], g_MLSs, g_lineMat);
            // console.log("第" + k + "个文件的MultiLineString");
        }
        g_MLSs.rotation.x = -0.5 * Math.PI;//赋值方式不会效果不会累加
        g_MLSs.rotation.z = -0.5 * Math.PI;

        rearrangeEid();
        initializeDAT();//必须在rearrangeEid之后被调用
        drawText();
        drawScatterMap();
        drawUnsualVideoPoints();
        drawFloorNumCanvas();
    }
}
function createMP() {

    for (var k = 0; k < g_smallFloorDatas.length; k++) {
        createMultiPolygon(g_binhaiSceneDatas[k], g_binhaiSceneMPolygons, g_binhaiSceneMat, 0);//20180611 为了不采用O函数
        createMultiPolygon(g_smallFloorDatas[k], g_smallFloorMPolygons, undefined, 1);
        //暂时先采用带O方法,暂缺部分eid。以后需分组加入，且使用eid
        //createMultiPolygon(g_bigFloorDatas[k],  g_bigFloorMPolygons, 2);
        //四边墙体与地板
        if (g_jsonNameAttrs[k] != 0) {
            var g_bigFloorBoardData = new Array(), g_bigFloorWallData = new Array(), g_bigFloorRoomData;  //存放地板、墙、房间数据的数组

            var floor = g_jsonNameAttrs[k].substr(1);

            g_bigFloorRoomData = g_bigFloorDatas[k].slice(0, g_bigFloorDatas[k].length - 2);  //房间数据

            if ((floor <= 221006) || (floor >= 221021 && floor <= 221026)  //没有分两边的层
                || (floor >= 221034 && floor <= 221038) || (floor > 221041)) {
                var data = g_bigFloorDatas[k].slice(g_bigFloorDatas[k].length - 1, g_bigFloorDatas[k].length);  //外壳数据
                var board = data[0].slice(0, 2);
                g_bigFloorBoardData.push(board)
                var wall = data[0].slice(1, data[0].length - 1);
                g_bigFloorWallData.push(wall)

            } else {
                var data = g_bigFloorDatas[k].slice(g_bigFloorDatas[k].length - 2, g_bigFloorDatas[k].length);  //外壳数据
                var board = data[0].slice(0, 1);
                g_bigFloorBoardData.push(board)
                var board1 = data[1].slice(0, 1);
                g_bigFloorBoardData.push(board1)

                var wall = data[0].slice(1, data[0].length - 1);
                g_bigFloorWallData.push(wall)
                var wall1 = data[1].slice(1, data[1].length - 1);
                g_bigFloorWallData.push(wall1)
            }

            createMultiPolygonO(g_bigFloorBoardData, g_bigFloorBoardMPolygons, g_bigFloorBoardMat,
                false, g_jsonNameAttrs[k]);
            createMultiPolygonO(g_bigFloorWallData, g_bigFloorWallMPolygons, g_bigFloorWallMat,
                false, g_jsonNameAttrs[k]);
            createMultiPolygonO(g_bigFloorRoomData, g_bigFloorRoomMPolygons, g_bigFloorRoomMat,
                false, g_jsonNameAttrs[k]);

        }
    }
    g_selectableMPolygons.rotation.x = -0.5 * Math.PI;//赋值方式不会效果不会累加
    g_selectableMPolygons.rotation.z = -0.5 * Math.PI;
    // g_selectableMPolygons.rotateY(-0.5*Math.PI);//函数调用方式效果会累加
    // g_selectableMPolygons.rotateX(-0.5*Math.PI);
    g_binhaiSceneMPolygons.rotation.x = -0.5 * Math.PI;
    g_binhaiSceneMPolygons.rotation.z = -0.5 * Math.PI;
    g_bigFloorBoardMPolygons.rotation.x = -0.5 * Math.PI;
    g_bigFloorBoardMPolygons.rotation.z = -0.5 * Math.PI;
    g_bigFloorWallMPolygons.rotation.x = -0.5 * Math.PI;
    g_bigFloorWallMPolygons.rotation.z = -0.5 * Math.PI;
    g_bigFloorRoomMPolygons.rotation.x = -0.5 * Math.PI;
    g_bigFloorRoomMPolygons.rotation.z = -0.5 * Math.PI;


    g_frameMPolygons.rotation.x = -0.5 * Math.PI;
    g_frameMPolygons.rotation.z = -0.5 * Math.PI;
}
function rearrangeEid() {
    for (var k = 0; k < g_smallFloorMPolygons.children.length; k++) {
        for (var m = 0; m < g_smallFloorMPolygons.children.length; m++) {

            var mStr = g_smallFloorMPolygons.children[m].name;
            var kStr = g_smallFloorMPolygons.children[k].name;
            if(m != k && g_smallFloorMPolygons.children[m].name == g_smallFloorMPolygons.children[k].name){
                    var ka = g_smallFloorMPolygons.children[k].geometry.boundingSphere.center;
                    var ma = g_smallFloorMPolygons.children[m].geometry.boundingSphere.center;
                    if(ka.y < ma.y) {//判断楼左侧还是右侧
                        var str = g_smallFloorMPolygons.children[m].name.substr(1);
                        g_smallFloorMPolygons.children[m].name = "2";
                        g_smallFloorMPolygons.children[m].name += str;
                    }else{
                        var str2 = g_smallFloorMPolygons.children[k].name.substr(1);
                        g_smallFloorMPolygons.children[k].name = "2";
                        g_smallFloorMPolygons.children[k].name += str2;
                    }
            }
        }
    }
}
function initScene() {
    var pathStr = "static/resource/440300223022_Building_webuilding_";
    for (var i = 1; i < 5; i++) {
        g_files.push(pathStr + "B" + i + ".geojson");
    }
    for (var i = 1; i < 51; i++) {
        g_files.push(pathStr + "F" + i + ".geojson");
    }
    g_files.push(pathStr + "all.json");
    g_files.push("static/resource/binhai_sence.json");

    for (var i = 0; i < g_files.length; i++) {
        $.getJSON(g_files[i], parseData);
    }

    generateContourRGB();
    $.getJSON("static/resource/trueHM.json", parseContourData);

    g_renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('mainCanvas'), antialias: true });
    g_renderer.setClearColor(0x2f2e2e); // black
    g_renderer.setSize(window.innerWidth, window.innerHeight);
    g_renderer.sortObjects = true;

    g_scene = new THREE.Scene();
    g_scene.add(g_selectableMPolygons);
    g_selectableMPolygons.add(g_smallFloorMPolygons);
    g_scene.add(g_binhaiSceneMPolygons);
    g_scene.add(g_MLSs);
    g_scene.add(g_MPoints);
    g_scene.add(g_bigFloorBoardMPolygons)
    g_scene.add(g_bigFloorWallMPolygons)
    g_scene.add(g_bigFloorRoomMPolygons)
    g_scene.add(g_frameMPolygons);

    // var axis = new THREE.AxesHelper(500);
    // g_scene.add(axis);

    g_ambientL = new THREE.AmbientLight(0xaaaaaa);
    g_scene.add(g_ambientL);

    g_spotLight = new THREE.SpotLight(0xffffff, 1);
    g_spotLight.position.set(318.0, 240.0, 665.0);
    g_scene.add(g_spotLight);

    //heatplanlist = CreateMultifloorPlane(g_scene);

    // camera
    camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 25000);
    camera.position.set(340, 173, 571);
    g_scene.add(camera);

    controls = new THREE.OrbitControls(camera, g_renderer.domElement);//创建控件对象
    controls.target = defaultCenterVeiw;
    controls.autoRotate = false;
    controls.maxPolarAngle = Math.PI * 0.45;//设置垂直旋转角最大值
    controls.minPolarAngle = Math.PI * 0.45;//设置垂直旋转角最小值
    controls.maxDistance = 1000;
    controls.minDistance = 200;
    //initStats();  //debug
    window.addEventListener('resize', onWindowResize, false);
    window.addEventListener('dblclick', ondblclick, false);
    //window.addEventListener('keydown', onkeydown, false);
    raycaster = new THREE.Raycaster();
    document.addEventListener('mousemove', onMouseMove, false);

    registerFrontEndCB(frontEndCB);   
}
function getGlobalInfo() {
    if (g_recordSelectedMesh == null)
        return;

    var name = g_recordSelectedMesh.name;
    var leftORright = parseInt(name.substr(0, 1));
    var underground = parseInt(name.substr(name.length - 6, 3));
    g_globalVar.floorNumber = parseInt(name.substr(name.length - 3, 3));

    if (leftORright == 1)
        g_globalVar.left = true;
    else if (leftORright == 2)
        g_globalVar.left = false;

    if (underground == 220)
        g_globalVar.underground = true;
    else if (underground == 221)
        g_globalVar.underground = false;

    if (g_globalVar.underground)
        g_globalVar.floorName = "B" + g_globalVar.floorNumber;
    else
        g_globalVar.floorName = "F" + g_globalVar.floorNumber;
}
function ondblclick(event) {//不知道如何判断左右鼠标按钮
    if (f_FloorOrBudling == 0) {  //在整栋楼视角下，双击进入单层
        if (g_recordSelectedMesh == null || !controls.enabled)
            return;

        floorTextShow(false);
        getGlobalInfo();
        inFloorEventForWeb(f_pageType, f_subPageType, getFloorNum(g_recordSelectedMesh));
        eyeFlyTo(g_recordSelectedMesh);

        g_keySpace = true;
        var curObj = g_recordSelectedMesh.name;

        g_bigFloorBoardMPolygons.visible = true;
        g_bigFloorWallMPolygons.visible = true;
        g_bigFloorRoomMPolygons.visible = true;

        for (var i = 0; i < g_bigFloorBoardMPolygons.children.length; i++)//在不采用O函数时，可能需要更深一步的访问
        {
            if (shortEidEqual(curObj, g_bigFloorBoardMPolygons.children[i].name)) {
                g_bigFloorBoardMPolygons.children[i].visible = true;
                g_bigFloorWallMPolygons.children[i].visible = true;
                g_bigFloorRoomMPolygons.children[i].visible = true;
            }
            else {
                g_bigFloorBoardMPolygons.children[i].visible = false;
                g_bigFloorWallMPolygons.children[i].visible = false;
                g_bigFloorRoomMPolygons.children[i].visible = false;
            }
        }
        g_smallFloorMPolygons.visible = false;
        g_frameMPolygons.visible = false;
        for(var i = 0;i<g_UnusualVideogroup.children.length;i++)
        {
            g_UnusualVideogroup.children[i].visible = false;
        }
        g_textgroup.visible = false;
        for (var i = 0; i < heatplanlist.length; ++i) {
            heatplanlist[i].visible = false;
        }

        var clickcenter = g_recordSelectedMesh.geometry.boundingSphere.center;
        //var pos = [clickcenter.y,clickcenter.z,clickcenter.x];
        if (floorHeatmapEvent.isShowheat(f_subPageType, g_contourKeys, g_contourData, g_globalVar.floorName, g_contourIndex)) {
            var position = [clickcenter.x, clickcenter.y, clickcenter.z];
            floorHeatmapEvent.stats = f_subPageType;
            heatplane = CreateHeatmapFrompos(position, g_scene, heatplane);
        }
        dbclickEvent(g_recordSelectedMesh);
    } else if (f_FloorOrBudling == 1) {  //在单层视角下，双击播放异常视频
        getGlobalInfo();
        console.log(selectVideo(event));  //获取异常视频点
    }

}
function shortEidEqual(name1, name2) {
    var s1 = name1.substr(1, name1.length - 1);
    var s2 = name2.substr(1, name2.length - 1);

    if (s1 == s2)
        return true;
    else
        return false;
}
function updateContour(colorIndex, time_key) {
    g_bigFloorBoardMPolygons.visible = false;
    g_bigFloorWallMPolygons.visible = false;
    g_bigFloorRoomMPolygons.visible = false;

    matchContourColor(colorIndex, time_key);

    for (var i = 0; i < heatplanlist.length; ++i) {
        heatplanlist[i].visible = false;
    }

    for(var i = 0;i<g_UnusualVideogroup.children.length;i++)
    {
        g_UnusualVideogroup.children[i].visible = false;
    }
    g_textgroup.visible = false;
    for (var i = 0; i < g_sandiangroup.children.length; i++) {
        g_sandiangroup.children[i].visible = false;
    }
    // for (var i = 0; i < g_Videogroup.children.length; i++) {
    //     g_Videogroup.children[i].visible = false;
    // }

}
function matchContourColor(colorIndex, time_key) {
    var dataByTime = g_contourData.get(time_key);
    for (var j = 0; j < g_smallFloorMPolygons.children.length; j++)//0.0~0.5  Color(1.0, gb, gb);
    {
        var col = g_contourColor[colorIndex][0];
        for (var [key, value] of dataByTime) {
            if (shortEidEqual(name2eid(key), g_smallFloorMPolygons.children[j].name)) {
                var index = parseInt(g_smallFloorMPolygons.children[j].name[0]) - 1;
                col = g_contourColor[colorIndex][value[index].y];
            }
        }
        g_smallFloorMPolygons.children[j].material.color.set(col);
        g_smallFloorMPolygons.children[j].material.needsUpdate = true;
        g_smallFloorMPolygons.children[j].material.transparent = true;
        g_smallFloorMPolygons.children[j].material.opacity = 0.2;
    }
}
function For3D_View_Report_Clicked() {
    console.log(g_sandiangroup);
    if (!g_smallFloorMPolygons.visible) {
        subPageChangeUsualFun();
    }
    var keyX = g_contourKeys[g_contourIndex++];
    if (g_contourIndex >= g_contourKeys.length)
        g_contourIndex = 0;
    updateContour(0, keyX);

    WEBUILDING3D.setMaterial(WEBUILDING3D.DefaultMaterial);
}
function For3D_Energy_Consumption_Heat_Map_Clicked() {
    if (!g_smallFloorMPolygons.visible) {
        subPageChangeUsualFun();
    }
    var keyX = g_contourKeys[g_contourIndex++];
    if (g_contourIndex >= g_contourKeys.length)
        g_contourIndex = 0;
    updateContour(0, keyX);

}
function For3D_Asset_Value_Density_Clicked() {
    if (!g_smallFloorMPolygons.visible) {
        subPageChangeUsualFun();
    }
    var keyX = g_contourKeys[g_contourIndex++];
    if (g_contourIndex >= g_contourKeys.length)
        g_contourIndex = 0;
    updateContour(1, keyX);

}
function For3D_Operation_Costs_Clicked() {
    if (!g_smallFloorMPolygons.visible) {
        subPageChangeUsualFun();
    }
    var keyX = g_contourKeys[g_contourIndex++];
    if (g_contourIndex >= g_contourKeys.length)
        g_contourIndex = 0;
    updateContour(2, keyX);

}
function For3D_Work_Order_Density_Clicked() {
    if (!g_smallFloorMPolygons.visible) {
        subPageChangeUsualFun();
    }
    for (var j = 0; j < g_smallFloorMPolygons.children.length; j++) {
        var col = g_contourColor[0][0];
        g_smallFloorMPolygons.children[j].material.color.set(col);
        g_smallFloorMPolygons.children[j].material.needsUpdate = true;
        g_smallFloorMPolygons.children[j].material.transparent = true;
        g_smallFloorMPolygons.children[j].material.opacity = 0.2;
    }

    for(var i = 0;i<g_UnusualVideogroup.children.length;i++)
    {
        g_UnusualVideogroup.children[i].visible = false;
    }
    g_textgroup.visible = false;
    for (var i = 0; i < g_sandiangroup.children.length; i++) {
        g_sandiangroup.children[i].visible = true;
    }

    var sprite1 = new THREE.CanvasTexture(generateSprite(0));

    var material1 = new THREE.SpriteMaterial({
        map: sprite1,
        blending: THREE.AdditiveBlending,
        depthTest: false
    });

    for (var i = 0; i < g_sandiangroup.children.length; i++) {
        for (var j = 0; j < g_sandiangroup.children[i].children.length; j++) {
            {
                g_sandiangroup.children[i].children[j].material = material1;
                g_sandiangroup.children[i].children[j].scale.x = g_sandiangroup.children[i].children[j].scale.y = 2;
            }
        }
    }
    // for (var i = 0; i < g_Videogroup.children.length; i++) {
    //     g_Videogroup.children[i].visible = false;
    // }
}
function For3D_Unusual_Video_Clicked() {
    if (!g_smallFloorMPolygons.visible) {
        subPageChangeUsualFun();
    }
    for (var j = 0; j < g_smallFloorMPolygons.children.length; j++) {
        var col = g_contourColor[0][0];
        g_smallFloorMPolygons.children[j].material.color.set(col);
        g_smallFloorMPolygons.children[j].material.needsUpdate = true;
        g_smallFloorMPolygons.children[j].material.transparent = true;
        g_smallFloorMPolygons.children[j].material.opacity = 0.2;
    }
    g_bigFloorBoardMPolygons.visible = false;
    g_bigFloorWallMPolygons.visible = false;
    g_bigFloorRoomMPolygons.visible = false;

    for (var i = 0; i < heatplanlist.length; ++i) {
        heatplanlist[i].visible = false;
    }
    for (var i = 0; i < g_sandiangroup.children.length; i++) {
        g_sandiangroup.children[i].visible = false;
    }
    // for (var i = 0; i < g_Videogroup.children.length; i++) {
    //     g_Videogroup.children[i].visible = false;
    // }
    for(var i = 0;i<g_UnusualVideogroup.children.length;i++)
    {
        g_UnusualVideogroup.children[i].visible = true;
    }
    g_textgroup.visible = true;


    //xsg for temp
    var colorR = 0xbf0000, colorB = 0x0000bf;
    for (var j = 0; j < g_smallFloorMPolygons.children.length; j++)//0.0~0.5  Color(1.0, gb, gb);
    {
        var fn = g_smallFloorMPolygons.children[j].name;
        var floorNO = parseInt(fn.substr(fn.length - 3, 3));
        var lr = parseInt(fn.substr(0, 1));
        if (floorNO >= 34 && floorNO <= 38) {//34~38随意设置的
            g_smallFloorMPolygons.children[j].material.color.set(colorR);
            g_smallFloorMPolygons.children[j].material.needsUpdate = true;
        } else if (lr == 2 && floorNO >= 16 && floorNO <= 20) {//16~20随意设置的
            g_smallFloorMPolygons.children[j].material.color.set(colorB);
            g_smallFloorMPolygons.children[j].material.needsUpdate = true;
        }
    }

}
function onkeydown(event) {//不知道如何判断左右鼠标按钮
    if (event.keyCode != 32)
        return;
    viewBackFromFloorToBudling();

    //测试
    // var fn = Math.round(Math.random()*50) ;
    // if(fn < 1)
    //   fn = 1;
    // eyeFlyToX(fn);
}
function viewBackFromFloorToBudling() {
    if (!g_keySpace || !controls.enabled)
        return;
    subPageChangeUsualFun();
    switch (f_subPageType) {
        case 1:
            For3D_Energy_Consumption_Heat_Map_Clicked();
            break;
        case 2:
            For3D_Asset_Value_Density_Clicked();
            break;
        case 3:
            For3D_Operation_Costs_Clicked();
            break;
        case 4:
            For3D_Work_Order_Density_Clicked();
            break;
        case 5:
            For3D_Unusual_Video_Clicked();
            break;
    }
}
function subPageChangeUsualFun() {
    outFloorEventForWeb(f_pageType, f_subPageType);
    eyeFlyBack();
    g_keySpace = false;

    g_bigFloorBoardMPolygons.visible = false;
    g_bigFloorWallMPolygons.visible = false;
    g_bigFloorRoomMPolygons.visible = false;

    for (var i = 0; i < g_bigFloorBoardMPolygons.children.length; i++) {//在不采用O函数时，可能需要更深一步的访问
        g_bigFloorBoardMPolygons.children[i].visible = false;
        g_bigFloorWallMPolygons.children[i].visible = false;
        g_bigFloorRoomMPolygons.children[i].visible = false;
    }

    g_smallFloorMPolygons.visible = true;
    g_frameMPolygons.visible = true;
}
function renderScene() {
    //g_stats.update();  //debug
    requestAnimationFrame(renderScene);
    createSceneDynamicly();

    mousemovePick();
    controls.update();
    g_renderer.render(g_scene, camera);
    viewMove();
    //updateheatTexture();
}
function viewMove() {
    //主要是相机的跟踪视点需要移动,相机位置其次
    if (farview == true) {
        if (g_countX < g_step) {
            g_countX++;
            camera.position.x += deltaX;
            camera.position.y += deltaY;
            camera.position.z += deltaZ;
        }
        else if (g_countX >= g_step) {
            g_countX = 0;
            farview = false;
            controls.enabled = true;
        }
    }
    if (nearview == true) {
        if (g_countX < g_step) {
            g_countX++;
            camera.position.x += deltaX;
            camera.position.y += deltaY;
            camera.position.z += deltaZ;
        } else if (g_countX >= g_step) {
            g_countX = 0;
            nearview = false;
            controls.enabled = true;
        }
    }
}
function eyeFlyTo(mesh) {
    var center;
    f_FloorOrBudling = 1;
    for (var i = 0; i < g_bigFloorBoardMPolygons.children.length; i++) {
        if (shortEidEqual(mesh.name, g_bigFloorBoardMPolygons.children[i].name)) {
            center = g_bigFloorBoardMPolygons.children[i].geometry.boundingSphere.center;
            break;
        }
    }
    controls.target = new THREE.Vector3(center.y, center.z, center.x);
    /***************************************/
    //楼层加一个光源

    g_floorDLight.position.set(center.y, center.z + 80, center.x);
    g_floorDLight.target = mesh;
    g_scene.add(g_floorDLight)


    /***************************************/
    farview = true;
    controls.enabled = false;
    controls.maxPolarAngle = Math.PI * 0.40;//设置垂直旋转角最大值
    controls.minPolarAngle = Math.PI * 0.0;//设置垂直旋转角最小值

    targetCameraX = 50 + center.y;
    targetCameraY = 150 + center.z;
    targetCameraZ = 50 + center.x;

    originCameraX = camera.position.x;
    originCameraY = camera.position.y;
    originCameraZ = camera.position.z;

    deltaX = (targetCameraX - originCameraX) / g_step;
    deltaY = (targetCameraY - originCameraY) / g_step;
    deltaZ = (targetCameraZ - originCameraZ) / g_step;
}
function eid2numX(name) {
    var floorNO = 0;
    var minus = name.substr(1, 3);
    var floor = name.substr(4, 6);
    if (minus == 220)
        floorNO = - parseInt(floor);
    else
        floorNO = parseInt(floor);

    return floorNO;
}
var floormesh = {};
function getRight(name) {
    var leftORright = parseInt(name.substr(0, 1));
    var underground = parseInt(name.substr(name.length - 6, 3));
    floormesh.floorNumber = parseInt(name.substr(name.length - 3, 3));

    if (leftORright == 1) {
        floormesh.left = true;
    }
    else if (leftORright == 2) {
        floormesh.left = false;
    }

    if (underground == 220) {
        floormesh.underground = true;

    }
    else if (underground == 221) {
        floormesh.underground = false;
    }

    if (g_globalVar.underground) {
        floormesh.floorName = "B" + floormesh.floorNumber;
    }
    else {
        floormesh.floorName = "F" + floormesh.floorNumber;
    }
}
function getGlobalInfoX(name) {
    var leftORright = parseInt(name.substr(0, 1));
    var underground = parseInt(name.substr(name.length - 6, 3));
    g_globalVar.floorNumber = parseInt(name.substr(name.length - 3, 3));

    if (leftORright == 1)
        g_globalVar.left = true;
    else if (leftORright == 2)
        g_globalVar.left = false;

    if (underground == 220)
        g_globalVar.underground = true;
    else if (underground == 221)
        g_globalVar.underground = false;

    if (g_globalVar.underground)
        g_globalVar.floorName = "B" + g_globalVar.floorNumber;
    else
        g_globalVar.floorName = "F" + g_globalVar.floorNumber;
}
function eyeFlyToX(floorNO) {
    var center, iRecord;
    for (var i = 0; i < g_bigFloorBoardMPolygons.children.length; i++) {
        if (floorNO == eid2numX(g_bigFloorBoardMPolygons.children[i].name)) {
            center = g_bigFloorBoardMPolygons.children[i].geometry.boundingSphere.center;
            iRecord = i;
            g_bigFloorBoardMPolygons.children[i].visible = true;
            g_bigFloorWallMPolygons.children[i].visible = true;
            g_bigFloorRoomMPolygons.children[i].visible = true;
        } else {
            g_bigFloorBoardMPolygons.children[i].visible = false;
            g_bigFloorWallMPolygons.children[i].visible = false;
            g_bigFloorRoomMPolygons.children[i].visible = false;
        }
    }

    controls.target = new THREE.Vector3(center.y, center.z, center.x);
    /***************************************/
    g_floorDLight.position.set(center.y, center.z + 80, center.x);
    g_floorDLight.target = g_bigFloorBoardMPolygons.children[iRecord];
    /***************************************/
    farview = true;
    controls.enabled = false;
    targetCameraX = 50 + center.y;
    targetCameraY = 150 + center.z;
    targetCameraZ = 50 + center.x;

    g_changeViewByNum = true;
    deltaX = (targetCameraX - camera.position.x) / g_step;
    deltaY = (targetCameraY - camera.position.y) / g_step;
    deltaZ = (targetCameraZ - camera.position.z) / g_step;

    getGlobalInfoX(g_bigFloorBoardMPolygons.children[iRecord].name);
    g_smallFloorMPolygons.visible = false;
    g_frameMPolygons.visible = false;
    for(var i = 0;i<g_UnusualVideogroup.children.length;i++)
    {
        g_UnusualVideogroup.children[i].visible = false;
    }
    g_textgroup.visible = false;
    for (var i = 0; i < heatplanlist.length; ++i) {
        heatplanlist[i].visible = false;
    }
    var clickcenter;
    for (var ps = 0; ps < heatplane.length; ++ps) {
        //g_scene.remove(heatplane[i]);
        heatplane[ps].visible = false;
    }
    for (var jc = 0; jc < g_smallFloorMPolygons.children.length; ++jc) {
        getRight(g_smallFloorMPolygons.children[jc].name);
        if (floormesh.floorNumber === floorNO && floormesh.left === false) {
            clickcenter = g_smallFloorMPolygons.children[jc].geometry.boundingSphere.center;
            if (floorHeatmapEvent.isShowheat(f_subPageType, g_contourKeys, g_contourData, g_globalVar.floorName, g_contourIndex)) {
                var position = [clickcenter.x, clickcenter.y, clickcenter.z];
                floorHeatmapEvent.stats = f_subPageType;
                heatplane = CreateHeatmapFrompos(position, g_scene, heatplane);
                break;
            }
        }
    }
    dbclickEvent();
    for (var i = 0; i < g_bigFloorBoardMPolygons.children.length; i++) {
        if (floorNO == eid2numX(g_bigFloorBoardMPolygons.children[i].name)) {
            console.log(g_bigFloorBoardMPolygons.children[i]);
            dbclickEvent(g_bigFloorBoardMPolygons.children[i]);
        }
    }
}
function eyeFlyBack() {
    if (g_changeViewByNum) {
        g_changeViewByNum = false;
        deltaX = (targetCameraX - originCameraX) / g_step;
        deltaY = (targetCameraY - originCameraY) / g_step;
        deltaZ = (targetCameraZ - originCameraZ) / g_step;
    }

    f_FloorOrBudling = 0;
    nearview = true;
    controls.enabled = false;
    controls.maxPolarAngle = Math.PI * 0.45;//设置垂直旋转角最大值
    controls.minPolarAngle = Math.PI * 0.45;//设置垂直旋转角最小值
    controls.target = defaultCenterVeiw;
    controls.update();
    deltaX = (originCameraX - camera.position.x) / g_step;
    deltaY = (originCameraY - camera.position.y) / g_step;
    deltaZ = (originCameraZ - camera.position.z) / g_step;    
    g_scene.remove(g_floorDLight)
    //add by lrs008
    for (var ps = 0; ps < heatplane.length; ++ps) {
        //g_scene.remove(heatplane[i]);
        heatplane[ps].visible = false;
    }
    //end add by lrs008
}
function onWindowResize() {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    g_renderer.setSize(window.innerWidth, window.innerHeight);
}
function onMouseMove(event) {
    event.preventDefault();
    mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
    mouse.y = - (event.clientY / window.innerHeight) * 2 + 1;
}
function mousemovePick() {
    camera.updateMatrixWorld();
    raycaster.setFromCamera(mouse, camera);
    var intersects = raycaster.intersectObjects(g_selectableMPolygons.children, true);
    if (intersects.length > 0) {
        if (g_recordSelectedMesh != intersects[0].object) {
            if (g_recordSelectedMesh)
                g_recordSelectedMesh.material = g_recordSelectedMat;
            g_recordSelectedMesh = intersects[0].object;
            g_recordSelectedMat = g_recordSelectedMesh.material;
            g_recordSelectedMesh.material = g_selectingMat;

            
        }
    } else {
        if (g_recordSelectedMesh) {
            g_recordSelectedMesh.material = g_recordSelectedMat;
        }
        g_recordSelectedMesh = null;
    }
    pickEvent();
}
function initStats() {
    g_stats = new Stats();
    g_stats.setMode(0);
    g_stats.domElement.style.position = 'absolute';
    g_stats.domElement.style.left = '0px';
    g_stats.domElement.style.top = '0px';
    document.getElementById("Stats-output").appendChild(g_stats.domElement);
}
function WebMouseClickEvent(typeValue) {
    if (typeValue == "eventClick_000") {
        For3D_View_Report_Clicked();
        f_subPageType = 0;
    }
    else if (typeValue == "eventClick_001") {
        For3D_Energy_Consumption_Heat_Map_Clicked();
        f_subPageType = 1;
    }
    else if (typeValue == "eventClick_002") {
        For3D_Asset_Value_Density_Clicked();
        f_subPageType = 2;
    }
    else if (typeValue == "eventClick_003") {
        For3D_Operation_Costs_Clicked();
        f_subPageType = 3;
    }
    else if (typeValue == "eventClick_004") {
        For3D_Work_Order_Density_Clicked();
        f_subPageType = 4;
    }
    else if (typeValue == "eventClick_005") {
        For3D_Unusual_Video_Clicked();
        f_subPageType = 5;
    }
}
function inFloorEventForWeb(type, subtype, floor) {
    // 上面导航  右侧导航  楼层
    console.log(type);
    console.log(subtype);
    console.log(floor)
    Vue.$store.state.threeD.chouseFloor = floor
    console.log(Vue.$store.state.threeD.chouseFloor)
    var obj = {
        type: type,
        subtype: subtype,
        floor: floor
    }
    if (type == 1) {
        if (subtype == 0) {
            Vue.$router.push({ path: '/home/appmainfloor', query: obj })
        } else if (subtype == 1) {
            Vue.$router.push({ path: '/home/energyfloor', query: obj })
        } else if (subtype == 2) {
            Vue.$router.push({ path: '/home/propertyfloor', query: obj })
        } else if (subtype == 3) {
            Vue.$router.push({ path: '/home/operationfloor', query: obj })
        } else if (subtype == 4) {
            Vue.$router.push({ path: '/home/workorderfloor', query: obj })
        } else if (subtype == 5) {
            Vue.$router.push({ path: '/home/Abnormalvideofloor', query: obj })
        }
    } else if (type == 2) {
    }
}
function outFloorEventForWeb(type, subtype) {

}
function getFloorNum(mesh) {
    var floor = mesh.name;
    var onbelow = floor.slice(1, 4);
    var newfloor = floor.slice(4, 7);
    return onbelow == 220 ? 0 - parseInt(newfloor) : parseInt(newfloor);
}
function getFloorNumFromNameId(num) {
    var floor = num;
    var onbelow = floor.slice(1, 4);
    var newfloor = floor.slice(4, 7);
    return onbelow == 220 ? 0 - parseInt(newfloor) : parseInt(newfloor);
}
function pickEvent() {

    if (g_recordSelectedMesh == null) {
        return;
    }
    if (g_lastRecordSelectedMesh == g_recordSelectedMesh) {
        return;
    }
    g_lastRecordSelectedMesh = g_recordSelectedMesh;
    floorTextPickShow();
    if (f_subPageType == 4) {
        var sprite1 = new THREE.CanvasTexture(generateSprite(0));

        var material1 = new THREE.SpriteMaterial({
            map: sprite1,
            blending: THREE.AdditiveBlending,
            depthTest: false
        });
        var sprite2 = new THREE.CanvasTexture(generateSprite(2));

        var material2 = new THREE.SpriteMaterial({
            map: sprite2,
            blending: THREE.AdditiveBlending,
            depthTest: false
        });
        for (var i = 0; i < g_sandiangroup.children.length; i++) {
            for (var j = 0; j < g_sandiangroup.children[i].children.length; j++) {
                if (i != getFloorNum(g_recordSelectedMesh) - 1) {
                    g_sandiangroup.children[i].children[j].material = material1;
                }
                else {
                    g_sandiangroup.children[i].children[j].material = material2;
                }
            }
        }

    }
    if (f_subPageType == 5) {
        var materical1 = new THREE.MeshBasicMaterial({
            color: 0xff0000
        });
        var materical2 = new THREE.MeshBasicMaterial({
            color: 0x00ffff
        });

        if (getFloorNum(g_recordSelectedMesh) == 18) {
            g_UnusualVideogroup.children[0].material = materical2;
            g_UnusualVideogroup.children[0].material.needsUpdate = true;
            g_UnusualVideogroup.children[1].material = materical1;
            g_UnusualVideogroup.children[2].material = materical1;
            g_UnusualVideogroup.children[3].material = materical1;
            g_UnusualVideogroup.children[1].material.needsUpdate = true;
            g_UnusualVideogroup.children[2].material.needsUpdate = true;
            g_UnusualVideogroup.children[3].material.needsUpdate = true;
        }
        else if (getFloorNum(g_recordSelectedMesh) == 36) {
            g_UnusualVideogroup.children[0].material = materical1;
            g_UnusualVideogroup.children[0].material.needsUpdate = true;
            g_UnusualVideogroup.children[1].material = materical2;
            g_UnusualVideogroup.children[2].material = materical2;
            g_UnusualVideogroup.children[3].material = materical2;
            g_UnusualVideogroup.children[1].material.needsUpdate = true;
            g_UnusualVideogroup.children[2].material.needsUpdate = true;
            g_UnusualVideogroup.children[3].material.needsUpdate = true;
        }
        else {
            g_UnusualVideogroup.children[0].material = materical1;
            g_UnusualVideogroup.children[0].material.needsUpdate = true;
            g_UnusualVideogroup.children[1].material = materical1;
            g_UnusualVideogroup.children[2].material = materical1;
            g_UnusualVideogroup.children[3].material = materical1;
            g_UnusualVideogroup.children[1].material.needsUpdate = true;
            g_UnusualVideogroup.children[2].material.needsUpdate = true;
            g_UnusualVideogroup.children[3].material.needsUpdate = true;
        }
    }
}
function dbclickEvent(mesh) {
    if (mesh == null) {
        return;
    }
    var floor = getFloorNum(mesh);
    if (f_subPageType == 4) {
        var sprite1 = new THREE.TextureLoader().load('static/textures/Maintenance_order.png');
        var sprite2 = new THREE.TextureLoader().load('static/textures/Public_maintenance.png');
        var sprite3 = new THREE.TextureLoader().load('static/textures/others.png');
        var sprite4 = new THREE.TextureLoader().load('static/textures/Inspection_list.png');

        var material1 = new THREE.SpriteMaterial({
            map: sprite1,
            //blending: THREE.AdditiveBlending,
            depthTest: false
        });
        var material2 = new THREE.SpriteMaterial({
            map: sprite2,
            //blending: THREE.AdditiveBlending,
            depthTest: false
        });
        var material3 = new THREE.SpriteMaterial({
            map: sprite3,
            //blending: THREE.AdditiveBlending,
            depthTest: false
        });
        var material4 = new THREE.SpriteMaterial({
            map: sprite4,
            //blending: THREE.AdditiveBlending,
            depthTest: false
        });
        for (var i = 0; i < g_sandiangroup.children.length; i++) {
            if (i != floor - 1) {
                g_sandiangroup.children[i].visible = false;
            }
            else {
                g_sandiangroup.children[i].visible = true;
                for (var j = 0; j < g_sandiangroup.children[i].children.length; j++) {
                    var randomnum = Math.ceil(Math.random() * 10) % 4;
                    if (randomnum == 0) {
                        g_sandiangroup.children[i].children[j].material = material1;
                    }
                    else if (randomnum == 1) {
                        g_sandiangroup.children[i].children[j].material = material2;
                    }
                    else if (randomnum == 2) {
                        g_sandiangroup.children[i].children[j].material = material3;
                    }
                    else if (randomnum == 3) {
                        g_sandiangroup.children[i].children[j].material = material4;
                    }
                    g_sandiangroup.children[i].children[j].scale.x = g_sandiangroup.children[i].children[j].scale.y = 8;
                }
            }

        }
    }
    if (f_subPageType == 5) {
        // var sprite1 = new THREE.TextureLoader().load('static/textures/halfball_machine.png');

        // var material1 = new THREE.SpriteMaterial({
        //     map: sprite1,
        //     //blending: THREE.AdditiveBlending,
        //     depthTest: false
        // });


        // for (var i = 0; i < g_Videogroup.children.length; i++) {
        //     if (i != floor - 1) {
        //         g_Videogroup.children[i].visible = false;
        //     }
        //     else {
        //         g_Videogroup.children[i].visible = true;
        //         for (var j = 0; j < g_Videogroup.children[i].children.length; j++) {
        //             g_Videogroup.children[i].children[j].material = material1;
        //         }
        //     }
        // }
        if(floor == 18)
        {
            g_UnusualVideogroup.children[0].visible = true;
            g_UnusualVideogroup.children[1].visible = false;
            g_UnusualVideogroup.children[2].visible = false;
            g_UnusualVideogroup.children[3].visible = false;
        }
        if(floor == 36)
        {
            g_UnusualVideogroup.children[0].visible = false;
            g_UnusualVideogroup.children[1].visible = true;
            g_UnusualVideogroup.children[2].visible = true;
            g_UnusualVideogroup.children[3].visible = true;
        }
    }
}

/**
 * 张英辉 2018/06/25 create
 * 双击获取异常视频点
 * @param {*} event 
 */
function selectVideo(event) {
    var x = (event.clientX / window.innerWidth) * 2 - 1;
    var y = - (event.clientY / window.innerHeight) * 2 + 1;
    camera.updateMatrixWorld();
    raycaster.setFromCamera(mouse, camera);
    if (!g_globalVar.underground) {  //暂时没有地下室的监控视频
        var videoFloorGroup = g_scene.getObjectByName("video-F" + g_globalVar.floorNumber); //获取该层存放异常视频点的group

        var intersects = raycaster.intersectObjects(videoFloorGroup.children, true);
        if (intersects.length > 0) {
            return intersects[0].object;
        }
    }

}